package tec.stan.ling.topo.graph.palette;

import org.eclipse.gef.requests.CreationFactory;

import tec.stan.ling.core.top.model.Device;
import tec.stan.ling.core.top.model.Subnet;
import tec.stan.ling.topo.model.NEFactory;
import tec.stan.ling.topo.util.ElementUtil;

/**
 * A factory to create Topo Element for Palette.
 * 
 * 该类通过Palette构造Topo对象。
 * 
 * @author Stan 张新潮
 * @since 2009-12-31
 */
public class PaletteCreationFactory implements CreationFactory {

	private PaletteObject type;

	public PaletteCreationFactory(PaletteObject type) {
		this.type = type;
	}

	@Override
	public Object getNewObject() {
		PaletteObject object = (PaletteObject) type;
		if (object.getObjectType().equals(Subnet.class)) {
			return NEFactory.getInstance().createSubnet();
		} else if (object.getObjectType().equals(Device.class)) {
			return NEFactory.getInstance().createDevice();
		}
		return null;
	}

	@Override
	public Object getObjectType() {
		return type.getObjectType();
	}

}
